package helper;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.List;

public class Tools 
{
	public static double get_li(double k)
	{
		double result=0;
		double v=0.001;
		double delta=k/100;
		
		for(int i=0;i<100;i++)
		{
			result+=-Math.log(1-v)/v*delta;
			v=v+delta;
		}
		
		return result;
	}
	
	public static void create_4d_csv_data_file(List<Object> head, List<List<Object>> data, String path)
	{
		File csv=null;
		BufferedWriter writer=null;
		try
		{
			csv=new File(path);
			writer=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(csv),"GBK"),1024);
			writeRow(head,writer);
			for(List<Object> row: data)
			{
				writeRow(row, writer);
			}
			writer.flush();
			writer.close();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
	private static void writeRow(List<Object> row, BufferedWriter writer) throws IOException
	{
		for(Object data: row)
		{
			StringBuffer sb=new StringBuffer();
			String rowStr=sb.append("\"").append(data).append("\",").toString();
			writer.write(rowStr);
		}
		writer.newLine();
	}
}
